package org.fdy.bgadmin.service.impl;

import com.alibaba.fastjson.JSON;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.fdy.bgadmin.res.*;
import org.fdy.bgadmin.service.HomeService;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/**
 * <p>描述：</p>
 *
 * @author fangdy
 * @create 2024-07-22 8:09
 */
@Slf4j
@Service
@RequiredArgsConstructor
public class HomeServiceImpl implements HomeService {
    @Override
    public List<CourseInfoRes> courseInfo(Integer tableSize) {
        List<CourseInfoRes> list = new ArrayList<>();
        CourseInfoRes courseInfoRes = null;
        int round = Math.round(100);
        for (int i = 0; i < tableSize; i++) {
            courseInfoRes = new CourseInfoRes();
            courseInfoRes.setName("课程" + i);
            courseInfoRes.setTodayBuy(i + round);
            courseInfoRes.setMonthBuy(i * 30 + round);
            courseInfoRes.setTotalBuy(i * 100 + round);
            list.add(courseInfoRes);
        }
        return list;
    }

    @Override
    public GraphicData graphicData() {
        GraphicData graphicData = new GraphicData();
        String videoStr = "[\n" +
                "          {\n" +
                "            name: '小米',\n" +
                "            value: 2999\n" +
                "          },\n" +
                "          {\n" +
                "            name: '苹果',\n" +
                "            value: 5999\n" +
                "          },\n" +
                "          {\n" +
                "            name: 'vivo',\n" +
                "            value: 1500\n" +
                "          },\n" +
                "          {\n" +
                "            name: 'oppo',\n" +
                "            value: 1999\n" +
                "          },\n" +
                "          {\n" +
                "            name: '魅族',\n" +
                "            value: 2200\n" +
                "          },\n" +
                "          {\n" +
                "            name: '三星',\n" +
                "            value: 4500\n" +
                "          }\n" +
                "        ]";
        List<VideoDataInfo> videoDataInfos = JSON.parseArray(videoStr, VideoDataInfo.class);
        graphicData.setVideoData(videoDataInfos);
        String userStr = "[\n" +
                "          {\n" +
                "            date: '周一',\n" +
                "            new: 5,\n" +
                "            active: 200\n" +
                "          },\n" +
                "          {\n" +
                "            date: '周二',\n" +
                "            new: 10,\n" +
                "            active: 500\n" +
                "          },\n" +
                "          {\n" +
                "            date: '周三',\n" +
                "            new: 12,\n" +
                "            active: 550\n" +
                "          },\n" +
                "          {\n" +
                "            date: '周四',\n" +
                "            new: 60,\n" +
                "            active: 800\n" +
                "          },\n" +
                "          {\n" +
                "            date: '周五',\n" +
                "            new: 65,\n" +
                "            active: 550\n" +
                "          },\n" +
                "          {\n" +
                "            date: '周六',\n" +
                "            new: 53,\n" +
                "            active: 770\n" +
                "          },\n" +
                "          {\n" +
                "            date: '周日',\n" +
                "            new: 33,\n" +
                "            active: 170\n" +
                "          }\n" +
                "        ]";
        List<UserDataInfo> userDataInfos = JSON.parseArray(userStr, UserDataInfo.class);
        graphicData.setUserData(userDataInfos);
        OrderDataInfo orderDataInfo = new OrderDataInfo();
        orderDataInfo.setXAxisData(Arrays.asList("20191001", "20191002", "20191003", "20191004", "20191005", "20191006", "20191007"));
        List<String> legendData = Arrays.asList("订单1", "订单2", "订单3", "订单4", "订单5", "订单6", "订单7");
        orderDataInfo.setLegendData(legendData);
        List<OrderInfo> series = new ArrayList<>();
        for (int i = 0; i < legendData.size(); i++) {
            String legendDatum = legendData.get(i);
            OrderInfo orderInfo = new OrderInfo();
            orderInfo.setName(legendDatum);
            orderInfo.setData(Arrays.asList(10 + i*10, 20+ i*10, 30+ i*10, 40+ i*10, 50+ i*10, 60+ i*10, 70+ i*10));
            series.add(orderInfo);
        }
        orderDataInfo.setSeries(series);
        graphicData.setOrderData(orderDataInfo);
        return graphicData;
    }
}
